package algorithm.practice;

import java.util.Arrays;

/**
 * @description: 类描述
 * @author: Fesine
 * @createTime:2017/8/1 10:28
 * @update:修改内容
 * @author: Fesine
 * @updateTime:2017/8/1 10:28
 */
public class SelectionSortPractice {

    public static void selectionSort(int[] a) {
        int n = a.length;
        for (int i = 0; i < n; i++) {
            int k = i;
            //从当前元素的下一个取数
            for (int j = i + 1; j < n; j++) {
                if (a[j] < a[k]) {
                    //获取最小值下标
                    k = j;
                }
            }
            //比较最小值与首位值
            if (k > i) {
                int tmp = a[i];
                a[i] = a[k];
                a[k] = tmp;
            }
        }
    }

    public static void main(String[] args) {
        int[] a = {3, 6, 4, 2,99, 11, 10, 5};
        selectionSort(a);
        System.out.println(Arrays.toString(a));
    }
}
